package Scrap;

import java.util.Scanner;

public class demo05_countwords {

	public static int countWords(String s) {

		int counter = 0;

		boolean word = false;
		int endOfLine = s.length() - 1;

		for (int i = 0; i < s.length(); i++) {
			
			if ((Character.isLetter(s.charAt(i))||(Character.isDigit(s.charAt(i)))== true && i != endOfLine)) {
				word = true;
			
			} else if (Character.isLetter(s.charAt(i))||(Character.isDigit(s.charAt(i)))== false && word == true) {
				counter++;
				word = false;
			
			} else if (Character.isLetter(s.charAt(i))||(Character.isDigit(s.charAt(i))) && i == endOfLine) {
				counter++;
			}
		}
		return counter;
	}
	
	
	public static void main(String[] args) {
		System.out.println("Please enter a string");
		Scanner s = new Scanner(System.in);
				
		int final_count=0;
		
		while(s.hasNextLine()){
			String str = s.nextLine();

	
			int count = countWords(str);
			final_count=final_count+count;     //entering Crtl Z is essential to confirm end of input
			
		}
		System.out.println(final_count);
		
		

	}

}
